#!/usr/bin/env python
import re, urllib2
# http://www.crummy.com/software/BeautifulSoup/documentation.html
from BeautifulSoup import BeautifulSoup

tip_number = 1504
tip_url = 'http://www.vim.org/tips/tip.php?tip_id=%d' % tip_number
tip_doc = urllib2.urlopen(tip_url)

soup = BeautifulSoup(tip_doc)
content = soup('table', cellpadding="0", cellspacing="0", border="0")[1]
info = content.findAll('table', cellpadding="0", cellspacing="0", border="0")[2]

created_complexity, author_version = info.findAll('tr')
created = created_complexity.findAll('td')[2].renderContents()
complexity = created_complexity.findAll('td')[6].renderContents()
author = author_version.findAll('td')[2].renderContents()
version = author_version.findAll('td')[6].renderContents()

body = content.findAll('p')[0].firstText()


print '''
Tip %(tip_number)d
Authored by %(author)s
Created on %(created)s
Complexity is %(complexity)s
Version of Vim required is '%(version)s'

%(body)s
''' % locals()


